/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
*/

package com.jinhe.tss.component.recycle.maintain;

import java.util.Collection;
import java.util.List;

import com.jinhe.tss.component.recycle.RecycleConfig;
import com.jinhe.tss.component.recycle.RecycleResource;
import com.jinhe.tss.component.support.web.webwork.PTActionSupport;
import com.jinhe.tss.core.web.dispaly.grid.GridDataEncoder;
import com.jinhe.tss.core.web.dispaly.tree.TreeEncoder;

/**
 * <p> RecycleAction.java </p>
 * <p>
 * 回收站操作Action
 * </p>
 */
public class RecycleAction extends PTActionSupport {
	
	private static final long serialVersionUID = 6808094457345236875L;
	
	public static final String RECYCLE_GRID_TEMPLATE = "template/recycle/grid/RecycleList.xml";

	private Long   recycleId; //回收站中的垃圾记录ID
	private Integer typeCode; //垃圾类型，在配置文件中配置
    
    private RecycleService recycleService;
    
    /**
     * <p>
     * 取回收站配置的类型组织成树结构
     * </p>
     * @return
     */
    public String getResTypeTree(){
    	Collection<RecycleResource> recycleResources = RecycleConfig.getInstance().getRecycleResources();
        TreeEncoder encoder = new TreeEncoder(recycleResources);
        encoder.setRootCanSelect(false);
        return print("AppTree", encoder);
    }
    
	/**
	 * <p>
	 * 物理删除，即将打伤删除标记的数据从数据库中删除
	 * </p>
	 * @return
	 */
	public String physicsDelete(){
		recycleService.physicsDelete(recycleId);
		return printSuccessMessage();
	}
	
	/**
	 * <p>
	 * 还原，即将打伤删除标记的数据删除标记重新去掉
	 * </p>
	 * @return
	 */
	public String recover(){
		recycleService.recover(recycleId);
		return printSuccessMessage();
	}
	
	/**
	 * <p>
	 * 显示回收站中某一种类型资源的所有垃圾信息
	 * </p>
	 * @return
	 */
	public String viewAll(){
		List<?> data = recycleService.getRecyledList(typeCode);
		GridDataEncoder encode = new GridDataEncoder(data, RECYCLE_GRID_TEMPLATE);
		return print("RecycleList",encode);
	}

	/**
	 * <p>
	 * 清空某种资源类型的回收站垃圾
	 * </p>
	 * @return
	 */
	public String clear(){
		recycleService.clearAll(typeCode);
		return printSuccessMessage();
	}

	public void setRecycleId(Long recycleId) {
		this.recycleId = recycleId;
	}

	public void setTypeCode(Integer typeCode) {
		this.typeCode = typeCode;
	}

	public void setRecycleService(RecycleService recycleService) {
		this.recycleService = recycleService;
	}
}
